package  instances
{
	import Box2D.Dynamics.b2FixtureDef;

	import flash.events.EventDispatcher;
	import flash.geom.Point;
	
	import noiseandheat.ane.box2d.Box2D;
	import noiseandheat.ane.box2d.data.b2BodyProxy;
	import noiseandheat.ane.box2d.data.b2VecProxy;
	
	public class ExtBox2DInstance extends EventDispatcher
	{
		private var _id:String;
		private var _type:String;
		private var _scale:Number;
		
		public var b2d:Box2D;
		public var body:b2BodyProxy;
		
		public var fixtureDef:b2FixtureDef;
		
		public function ExtBox2DInstance()
		{
		}
		
		public function set id(pId:String):void
		{
			_id = pId;
		}
		
		public function get id():String
		{
			return _id;
		}
		
		public function set type(pType:String):void
		{
			_type = pType;
		}
		
		public function get type():String
		{
			return _type;
		}
		public function set scale(pScale:Number):void{
			_scale = pScale;
		}
		public function get scale():Number{
			return _scale;
		}
		
		public function setTransform(point:Point,rotation:Number):void{
			b2d.setTransform(body.id,new Point(point.x / scale, point.y / scale),rotation * Math.PI/180);
		}
		
		public function setPosition(point:Point):void
		{
			b2d.setBodyPosition(body.id, new Point(point.x / scale, point.y / scale));
		}
		
		public function setRotation(rotation:Number):void
		{
			b2d.setBodyRotation(body.id,rotation * Math.PI/180);
		}
		
		public function getRotation():Number
		{
			return body.angle * 180/Math.PI;
		}
		
		public function getPosition():Point
		{
			return new Point(body.position.x * scale,body.position.y * scale);
		}
		
		public function getWorldCenter():Point{
			var v2:b2VecProxy = b2d.getBodyWorldCenter(body.id);
			return new Point(v2.x * scale,v2.y * scale);
		}
		
		public function updateBody(element:Object):void
		{
		}
	}
}